import Https from "@/utils/Https";
import { Card, Form, InputNumber, message, Spin } from "antd";
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import styles from "./styles.less";
const BaseSet = forwardRef((props, ref) => {
  const [form] = Form.useForm();
  const [loading, setLoading] = useState(false);
  const getDetails = async () => {
    setLoading(true);
    let res: any = await Https.get("/system/appointSet/info", {}, true);
    setLoading(false);
    if (res.code == 200 && res.data) {
      form.setFieldsValue({ ...res.data });
    } else {
      message.error(res.msg);
    }
  };
  useImperativeHandle(ref, () => ({
    changeVal: () => {
      form
        .validateFields()
        .then(async (values) => {
          let params = {
            ...values,
          };
          setLoading(true);
          let res: any = await Https.post(
            "/system/appointSet/addOrUpdateOne",
            params,
            true
          );
          if (res.code == 200) {
            message.success("操作成功");
          } else {
            message.error(res.msg);
          }
          setLoading(false);
        })
        .catch((errorInfo) => {
          console.log(errorInfo, "-errorInfo");
        });
    },
  }));
  useEffect(() => {
    getDetails();
  }, []);
  return (
    <Spin spinning={loading}>
      <div className={styles.BaseSet}>
        <Card title="基础设置">
          <Form form={form} colon={false}>
            <Form.Item label="id" name="id" hidden></Form.Item>
            <Form.Item
              label="可预约天数"
              required={true}
              tooltip={
                <img
                  style={{ width: "200px", height: "auto" }}
                  src="https://oss.zkwcloud.com/2024/07/16/0438109f10c247bea2fec25e9d3dadc2.png"
                ></img>
              }
            >
              会员最多可预约
              <Form.Item
                label=""
                name="maxAppointDay"
                rules={[
                  {
                    required: true,
                    message: "请输入预约天数",
                  },
                ]}
              >
                <InputNumber
                  min={1}
                  precision={0}
                  placeholder="请输入"
                  controls={false}
                  suffix={"天"}
                />
              </Form.Item>
              的课程,1表示当天
            </Form.Item>
          </Form>
        </Card>
      </div>
    </Spin>
  );
});
export default BaseSet;
